package com.pzhu;

import com.pzhu.domain.Brand;
import com.pzhu.mapper.BrandMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class App2 {
    public static void main(String[] args) throws IOException {
        String resouce = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resouce);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        SqlSession sqlSession = sqlSessionFactory.openSession();
//        //3. 获取Mapper接口的代理对象
        BrandMapper brandMapper = sqlSession.getMapper(com.pzhu.mapper.BrandMapper.class);
        List<Brand> brands = brandMapper.selectAll();
        System.out.println(brands);
        //5. 释放资源
        sqlSession.close();

    }
}
